<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="layout/template.xhtml">

<ui:define name="body">

    <h:form id="flight" styleClass="edit">

        <rich:panel>
            <f:facet name="header">#{flightHome.managed ? 'Edit' : 'Add'} Flight</f:facet>


            <s:decorate id="idField" template="layout/edit.xhtml">
                <ui:define name="label">Id</ui:define>
                <h:inputText id="id"
                       required="true"
                       disabled="#{flightHome.managed}"
                          value="#{flightHome.instance.id}">
                    <a:support event="onblur" reRender="idField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>



            <s:decorate id="nameField" template="layout/edit.xhtml">
                <ui:define name="label">Name</ui:define>
                <h:inputText id="name"
                           size="20"
                      maxlength="20"
                          value="#{flightHome.instance.name}">
                    <a:support event="onblur" reRender="nameField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <div style="clear:both">
                <span class="required">*</span>
                required fields
            </div>

        </rich:panel>

        <div class="actionButtons">

            <h:commandButton id="save"
                          value="Save"
                         action="#{flightHome.persist}"
                       disabled="#{!flightHome.wired}"
                       rendered="#{!flightHome.managed}"/>

            <h:commandButton id="update"
                          value="Save"
                         action="#{flightHome.update}"
                       rendered="#{flightHome.managed}"/>

            <h:commandButton id="delete"
                          value="Delete"
                         action="#{flightHome.remove}"
                      immediate="true"
                       rendered="#{flightHome.managed}"/>

            <s:button id="cancelEdit"
                   value="Cancel"
             propagation="end"
                    view="/Flight.xhtml"
                rendered="#{flightHome.managed}"/>

            <s:button id="cancelAdd"
                   value="Cancel"
             propagation="end"
                    view="/#{empty flightFrom ? 'FlightList' : flightFrom}.xhtml"
                rendered="#{!flightHome.managed}"/>

        </div>
    </h:form>

<rich:tabPanel switchType="ajax">

    <rich:tab label="Buses">
        <h:form styleClass="association" id="busesChildren">

            <h:outputText value="There are no buses associated with this flight."
                       rendered="#{empty flightHome.buses}"/>

            <rich:dataTable value="#{flightHome.buses}"
                           var="_bus"
                      rendered="#{not empty flightHome.buses}"
                    rowClasses="rvgRowOne,rvgRowTwo"
                            id="busesTable">
                <rich:column sortBy="#{_bus.id}">
                    <f:facet name="header">Id</f:facet>
                    <h:outputText value="#{_bus.id}"/>
                </rich:column>
                <rich:column sortBy="#{_bus.name}">
                    <f:facet name="header">Name</f:facet>
                    <h:outputText value="#{_bus.name}"/>
                </rich:column>
            </rich:dataTable>

        </h:form>

        <f:subview rendered="#{flightHome.managed}" id="buses">
        <div class="actionButtons">
            <s:button id="addbus"
                   value="Add bus"
                    view="/BusEdit.xhtml"
             propagation="none">
                 <f:param name="flightId"
                         value="#{flightHome.instance.id}"/>
                 <f:param name="busFrom" value="Flight"/>
            </s:button>
        </div>
        </f:subview>
    </rich:tab>
</rich:tabPanel>
</ui:define>

</ui:composition>
